home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archivers / XpkDisk / xdname.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  2KB  |  96 lines

  1. /*-
  2.  * XDNAME.C
  3.  *
  4.  * Give info about the file names used for tracks.
  5.  *
  6.  * $Id: xdname.c,v 1.3 1995/04/08 20:23:48 Rhialto Exp $
  7.  * $Log: xdname.c,v $
  8.  * Revision 1.3  1995/04/08  20:23:48  Rhialto
  9.  * Add/correct version strings.
  10.  *
  11.  * Revision 1.2  1993/11/08  13:18:19  Rhialto
  12.  * Add RCS tags.
  13.  *
  14.  * This code is (C) Copyright 1993,1995 by Olaf Seibert. All rights reserved.
  15.  * May not be used or copied without a licence.
  16. -*/
  17. #include "xpkdisk.h"
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22.  
  23. static const char idString[] = "\0$VER: xdName " STR(VERSION) "." STR(REVISION) "\r\n";
  24. static const char rcsId[] = "$Id: xdname.c,v 1.3 1995/04/08 20:23:48 Rhialto Exp $";
  25. static const char OldFile[]= "Track%03x";
  26.  
  27. #define HASHTABLESIZE    72    /* Must be less than 13*13 */
  28.  
  29. void
  30. OldName(char *filename, int track)
  31. {
  32.     sprintf(filename, OldFile, track);
  33. }
  34.  
  35. int
  36. main(int argc, char **argv)
  37. {
  38.     char        oldname[64];
  39.     char        newname[64];
  40.     int         new2old = 0;
  41.     int         number = 0;
  42.     int         maxtrack;
  43.     int         hash;
  44.     int         i;
  45.  
  46.     if (argc < 2) {
  47.     usage:
  48.     printf("Usage: XDName [-r] [-n] <track>\n");
  49.     exit(10);
  50.     }
  51.  
  52.     while (argv[1][0] == '-') {
  53.     switch (argv[1][1]) {
  54.     case 'r':
  55.         new2old = 1;
  56.         break;
  57.     case 'n':
  58.         number = 1;
  59.         break;
  60.     default:
  61.         goto usage;
  62.     }
  63.     argv++;
  64.     argc--;
  65.     }
  66.     maxtrack = strtol(argv[1], NULL, 0);
  67.  
  68.     if (number) {
  69.     NewName(newname, maxtrack);
  70.     hash = Hash(strrchr(newname, '/') + 1) % HASHTABLESIZE;
  71.     printf("Track %d is %s ; hash = %d\n", maxtrack, newname, hash);
  72.  
  73.     return 0;
  74.     }
  75.  
  76.     printf("failat 31\n");
  77.     for (i = 0; i <= maxtrack; i++) {
  78.     if (!new2old && i % HASHTABLESIZE == 0) {
  79.         NewName(newname, i);
  80.         *strrchr(newname, '/') = '\0';
  81.         hash = Hash(newname) % HASHTABLESIZE;
  82.         printf("makedir %s ; hash = %d\n", newname, hash);
  83.     }
  84.     OldName(oldname, i);
  85.     NewName(newname, i);
  86.     if (new2old) {
  87.         hash = Hash(oldname) % HASHTABLESIZE;
  88.         printf("rename %s to %s ; hash = %d\n", newname, oldname, hash);
  89.     } else {
  90.         hash = Hash(strrchr(newname, '/') + 1) % HASHTABLESIZE;
  91.         printf("rename %s to %s ; hash = %d\n", oldname, newname, hash);
  92.     }
  93.     }
  94.     return 0;
  95. }
  96.